package com.example.lenovo.a203_yhy_ordering_3.model;

import com.example.lenovo.a203_yhy_ordering_3.beans.UpdateUserBean;
import com.example.lenovo.a203_yhy_ordering_3.iface.UpdateUserIface;
import com.example.lenovo.a203_yhy_ordering_3.listener.UpdateUserListener;
import com.example.lenovo.a203_yhy_ordering_3.service.UpdateUserService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2018/12/16.
 */

public class UpdateUserModel implements UpdateUserIface{

    private Retrofit retrofit;


    public UpdateUserModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }




    @Override
    public void getUpdateUserResult(int user_id, String username, String userpass, String mobilenum, String address, final UpdateUserListener updateUserListener) {
        UpdateUserService updateUserService = retrofit.create(UpdateUserService.class);
        Call<UpdateUserBean> updateUserBeanCall =updateUserService.updateUserById(user_id,username,userpass,mobilenum,address);
        updateUserBeanCall.enqueue(new Callback<UpdateUserBean>() {
            @Override
            public void onResponse(Call<UpdateUserBean> call, Response<UpdateUserBean> response) {
                if(response!=null)
                    updateUserListener.onResponse(response.body());
                else
                    updateUserListener.onFail("修改信息失败");
            }

            @Override
            public void onFailure(Call<UpdateUserBean> call, Throwable t) {
                updateUserListener.onFail(t.toString());
            }
        });

    }
}
